package com.ruoyi.project.labappointment.mapper;

import com.ruoyi.project.lab.domain.LabAppointmentDto;
import com.ruoyi.project.labappointment.domain.AddList;
import com.ruoyi.project.labappointment.domain.AddListParam;
import com.ruoyi.project.labappointment.domain.ApplyParam;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

public interface LabAppointmentMapper {

    List<AddList> selectAddList(AddListParam addListParam);

    @Select("select id from lab_date where lab_id=#{applyParams.labId} and classtime_id=#{applyParams.section} and date_format(order_time, '%Y-%m-%d')=#{applyParams.applyTime} and status=2")
    Long selectLabTime(@Param("applyParams") ApplyParam applyParams);

    @Update("update lab_date set status=1 where lab_id=#{applyParams.labId} and classtime_id=#{applyParams.section} and date_format(order_time, '%Y-%m-%d')=#{applyParams.applyTime}")
    void updateLabDate(@Param("applyParams")ApplyParam applyParams);

    List<LabAppointmentDto> selectAppointemntSelect(@Param("addListParam") AddListParam addListParam, @Param("userId")Long userId);

    void addLabAppointment(Map<String, Object> map);

    @Delete("delete from lab_subscribe where id=#{id}")
    int quitApply(@Param("id") Long id);

    @Select("select lab_date_id from lab_subscribe where id=#{id}")
    Long selectlabDateIdById(@Param("id")Long id);

    @Update("update lab_date set status=2 where id=#{id}")
    void updateLabDateStatus(@Param("id") Long labDateId);//

    @Select("select id from tb_lab where lab_status=0 LIMIT 1")
    Long selectFirstLabId();

    /**
     * 通通过预约
     * @param id
     * @return
     */
    @Update("update lab_subscribe set status=1 where id=#{id}")
    Boolean goOut(Long id);

    /**
     * 拒绝
     */
    @Update("update lab_subscribe set status=0 where id=#{id}")
    Boolean refuse(Long id);

    /**
     * 删除预约
     */
    boolean deleteAppointment(String[] ids);

    /**
     * 实验室状态更新
     */
    boolean updateAppointmentStatus(String[] ids);

}
